/*
 * Copyright 2007-2008  Lukasz Laszko lukaszlaszko@gmail.com
 * 
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for any purpose and without fee is hereby
 * granted, provided that the above copyright notice appear in all
 * copies and that both that the copyright notice and this
 * permission notice and warranty disclaimer appear in supporting
 * documentation, and that the name of the author not be used in
 * advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.
 * 
 * The author disclaim all warranties with regard to this
 * software, including all implied warranties of merchantability
 * and fitness.  In no event shall the author be liable for any
 * special, indirect or consequential damages or any damages
 * whatsoever resulting from loss of use, data or profits, whether
 * in an action of contract, negligence or other tortious action,
 * arising out of or in connection with the use or performance of
 * this software. 
 */
package org.pg.biomedics.asr.mpeg7;

import java.util.List;
import java.util.ArrayList;

import org.simpleframework.xml.Root;
import org.simpleframework.xml.ElementList;

/**
 * A WordLexicon is a list of words, generally the vocabulary of a word-based
 * recognizer. Each entry of the lexicon is an identifier (generally its orthographic
 * representation) representing a word. A WordLexicon consists of the following
 * elements:
 * • phoneticAlphabet: is the name of an encoding scheme for phonetic symbols. It
 *   is only needed if phonetic representations are used (see below). The possible
 *   values of this attribute are indicated in the PhoneLexicon section.
 * • NumOfOriginalEntries: is the original size of the lexicon. In the case of a
 *   word lexicon, this should be the number of words originally known to the
 *   ASR system.
 * • A series of Token elements: each one stores an entry of the lexicon.
 * 
 * @author Lukasz Laszko
 */
@Root(name="WordLexicon")
public class WordLexicon extends Lexicon
{
    // <editor-fold desc="Fields">
    
    private List<WordToken> tokens = new ArrayList<WordToken>();    
    
    // </editor-fold>
    
    // <editor-fold desc="Properties">
    
    /**
     * Gets reference to tokens list
     * @return list of tokens
     */
    @ElementList(inline=true)
    public List<WordToken> getTokens()
    {
        return tokens;
    }
    
    /**
     * Sets toeks list. This method is utilized internally by xml serializer only
     * @param tokens list of tokens
     */
    @ElementList(inline=true)
    void setTokens(List<WordToken> tokens)
    {
        this.tokens = tokens;
    }
    
    // </editor-fold>
    
    // <editor-fold desc="Methods">
    
    /**
     * Get reference index number for token by word encapsulated by this token
     * @param word 
     * @return -1 - word doesn't exist on tokens list, > -1 - token index
     */
    public int getWordIndex(String word)
    {
        for (int i = 0; i < this.tokens.size(); i++)
        {
            WordToken wordToken = this.tokens.get(i);            
            if (wordToken == null)
                continue;
            
            if (word.equals(wordToken.getWord()))
                return i;
        }
        
        return -1;
    }   
    
    // </editor-fold>
}
